package com.sj.parksdk.fragment.pay;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sj.parksdk.R;
import com.sj.parksdk.R2;
import com.sj.parksdk.core.BaseFragment;
import com.sj.parksdk.setting.Extras;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xrouter.annotation.AutoWired;
import com.xuexiang.xrouter.launcher.XRouter;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.alpha.XUIAlphaImageView;
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;

import butterknife.BindView;

@Page(params = {Extras.BASE_TITLE, Extras.BASE_SUCCESS_TYPE, Extras.BASE_TYPE, Extras.BASE_CODE})
public class FragmentPayResult extends BaseFragment {
    @BindView(R2.id.iv_state)
    ImageView ivState;
    @BindView(R2.id.tv_content)
    TextView tvContent;
    @BindView(R2.id.btn_scan)
    SuperButton btnScan;
    @BindView(R2.id.iv_finish)
    XUIAlphaImageView ivFinish;
    @BindView(R2.id.toolbar_title)
    TextView tvTitle;

    @AutoWired(name = Extras.BASE_TITLE)
    String title;
    @AutoWired(name = Extras.BASE_SUCCESS_TYPE)
    boolean success;
    @AutoWired(name = Extras.BASE_CODE)
    String message;
    @AutoWired(name = Extras.BASE_TYPE)
    String btnStr;

    @Override
    protected void initArgs() {
        XRouter.getInstance().inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.parksdk_fragment_qrcode_success;
    }

    @Override
    protected TitleBar initTitle() {
        return null;
    }

    @Override
    protected void initViews() {
        if (success) ivState.setImageResource(R.drawable.park_ic_success);
        else ivState.setImageResource(R.drawable.park_ic_error);
        tvContent.setText(message);
        btnScan.setText(btnStr);
        tvTitle.setText(title);
    }

    @Override
    protected void initListeners() {
        btnScan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popToBack();
            }
        });
        ivFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
    }
}
